﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace ICalendar
{
    public class XParameterCollection : Dictionary<string, string>
    {

        public  XAttribute[] GetXAttributes()
        {
            var result = new List<XAttribute>();

            foreach (var item in this)
            {
                if (item.Value != null)
                {
                    string value = item.Value.Replace("\"", "");
                    if (value != "")
                        result.Add(new XAttribute(item.Key.ToLowerInvariant(), value));
                }
            }

            return result.ToArray();
        }

        public void SetXParams(XAttribute[] attrs)
        {
            foreach (var attr in attrs)
            {
                this[attr.Name.LocalName.ToUpperInvariant()] = attr.Value;
            }
        }

        public  string GetValue(string key)
        {
            string value;
            return TryGetValue(key, out value) ? value : null;
        }
    }
}
